package Five;

import java.util.Scanner;

class Car {
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}

	private int id;
	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			String s = scan.next();
			if (s.equals("quit")) {
				break;
			} else if (s.equals("Integer")) {
				System.out.println("Integer Test");
				ArrayListGeneralStack<Integer> list = new ArrayListGeneralStack<Integer>();
				int m = scan.nextInt();
				int n = scan.nextInt();
				for (int i = 0; i < m; i++) {
					int x = scan.nextInt();
					x = list.push(x);
					System.out.println("push:" + x);
				}
				int sum = 0;
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + list.pop());
				}
				System.out.println(list);
				while (!list.empty()) {
					sum += list.pop();
				}
				System.out.println("sum=" + sum);
				System.out.println(s.getClass().getInterfaces()[0]);
			} else if (s.equals("Double")) {
				System.out.println("Double Test");
				ArrayListGeneralStack<Double> list = new ArrayListGeneralStack<Double>();
				int m = scan.nextInt();
				int n = scan.nextInt();
				for (int i = 0; i < m; i++) {
					Double x = scan.nextDouble();
					x = list.push(x);
					System.out.println("push:" + x);
				}
				Double sum = 0.0;
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + list.pop());
				}
				System.out.println(list);
				while (!list.empty()) {
					sum += list.peek();
					Double t = list.pop();
				}
				System.out.println("sum=" + sum);
				System.out.println(list.getClass().getInterfaces()[0]);
			} else if (s.equals("Car")) {
				System.out.println("Car Test");
				ArrayListGeneralStack<Car> list = new ArrayListGeneralStack<Car>();
				int m = scan.nextInt();
				int n = scan.nextInt();
				for (int i = 0; i < m; i++) {
					Car car = new Car();
					car.setId(scan.nextInt());
					car.setName(scan.next());
					list.push(car);
					System.out.println("push:" + car.toString());
				}
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + list.pop().toString());
				}
				System.out.println(list);
				while (!list.empty()) {
					System.out.println(list.peek().getName());
					Car car = list.pop();
				}
				System.out.println(list.getClass().getInterfaces()[0]);
			} else if (s.equals("quit")) {
				break;
			}
		}
	}
}

